package com.meiqiongproperty.yiguanjia.fragment.order.orderAdapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.meiqiongproperty.yiguanjia.R;
import com.meiqiongproperty.yiguanjia.httpbean.order.OrderDetailListBean;

import java.util.ArrayList;
import java.util.List;

/**
 * author: Administrator
 * date: 2017/6/19.
 * package:com.meiqiongproperty.yiguanjia.fragment.order.orderAdapter
 */

public class OrderDetailListCenterAdapter extends BaseAdapter {
    private Context context;
    List<OrderDetailListBean.OrderdetailBean.ShopOrderInfoBean.SubOrderDetailBean> list_sub_order_info = new ArrayList<>();
    LayoutInflater inflater;

    public OrderDetailListCenterAdapter(Context context, List<OrderDetailListBean.OrderdetailBean.ShopOrderInfoBean.SubOrderDetailBean> list_sub_order_info) {
        this.context = context;
        this.list_sub_order_info = list_sub_order_info;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list_sub_order_info.size();
    }

    @Override
    public Object getItem(int position) {
        return list_sub_order_info.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder = null;
        if (convertView == null) {
            holder = new Holder();
            convertView = inflater.inflate(R.layout.confirm_order_list_center_item, null);
            holder.imageView = (ImageView) convertView.findViewById(R.id.image_order_detail_list_center);
            holder.productName = (TextView) convertView.findViewById(R.id.order_detail_list_product_name);
            holder.product_per_price = (TextView) convertView.findViewById(R.id.order_detail_list_product_per_price);
            holder.product_num = (TextView) convertView.findViewById(R.id.order_product_amount);
            convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }
        OrderDetailListBean.OrderdetailBean.ShopOrderInfoBean.SubOrderDetailBean bean = list_sub_order_info.get(position);
        Glide.with(context).load(bean.getProductImg()).into(holder.imageView);
        holder.productName.setText(bean.getProductName());
        holder.product_per_price.setText("￥" + bean.getProductPrice());
        holder.product_num.setText("x" + bean.getProductNum());
        return convertView;
    }

    class Holder {
        ImageView imageView;
        TextView productName;
        TextView product_per_price;
        TextView product_num;
    }
}
